import os
import sys
import logging

from django.core.management.base import BaseCommand

class Command(BaseCommand):
  args = "model method object_id"
  
  def handle(self, *args, **options):
    if len(args) != 1:
      self.print_help(sys.argv[0], sys.argv[1])
      return

    from jobs.models import Job, LOG
    # Ensure that job log messages will be sent to the standard output
    # thus caught in the job's log
    LOG.addHandler(logging.StreamHandler(sys.stdout))
    LOG.setLevel(logging.INFO)

    return Job.objects._exec_task(*args)

